import { Redirect, Route, Switch } from 'react-router-dom'

import RouterConfig from '../../config/RouterConfig'

const isAuth = () => {
  return localStorage.getItem('token')
}

const ContentDetails = () => {
  return (
    <Switch>
      {RouterConfig.map((item) => (
        <Route
          exact
          key={item.key}
          path={item.to}
          render={() => {
            if (!!isAuth()) {
              return <item.content />
            }
            return <Redirect to='/login' />
          }}
        />
      ))}
      <Redirect to='/dashboard' />
    </Switch>
  )
}

export default ContentDetails
